/*
 * main.c
 *
 * test event hub routines
 *
 * Copyright (C) 2020 Long-Horn
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h> 
#include <sys/time.h> 
#include <fcntl.h>
#include <limits.h>
#include <string.h> 
#include <errno.h>
#include <pthread.h>

#include "event_hub.h"

static event_callback_s event_cb;

static void print_event_payload(void *event, char *call_name)
{
    event_s *pevent = (event_s *)event;
    
    printf("\n%s: event->payload_len=%ld \n", call_name, pevent->payload_len);
    
    int i;
    
    for (i=0; i<pevent->payload_len; i++) {
        if( i >0 && (i%8 == 0)) printf("\n");
        printf("0x%02x ", pevent->payload[i]);
    }
    
    printf("\n");
}

static void event_callback(void *event)
{
    print_event_payload(event, "event_callback");
}

int main(int argc, char **argv)
{
    int res;
    event_hub_s *event_hub;
    
    event_cb.callback = event_callback;
    
    if ((res = create_event_hub(&event_hub)) < 0) {
        return -1;
    }
    
    event_hub_register_callback(event_hub, &event_cb);
    
    event_hub->start(event_hub);
    
    while(1) {
        
        sleep(1);
    }
}
